package com.home.demo.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.home.demo.common.utils.PageUtils;
import com.home.demo.common.utils.Query;

import com.home.demo.dao.ApplyDao;
import com.home.demo.entity.ApplyEntity;
import com.home.demo.service.ApplyService;
import org.springframework.util.StringUtils;


@Service("applyService")
public class ApplyServiceImpl extends ServiceImpl<ApplyDao, ApplyEntity> implements ApplyService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String status = (String) params.get("status");
        String userId = (String) params.get("userId");
        String careId = (String) params.get("careId");
        IPage<ApplyEntity> page = this.page(
                new Query<ApplyEntity>().getPage(params),
                new QueryWrapper<ApplyEntity>()
                .eq(StringUtils.hasText(status),"status",status)
                .eq(StringUtils.hasText(userId),"user_id",userId)
                .eq(StringUtils.hasText(careId),"medic_id",careId)
        );

        return new PageUtils(page);
    }

    @Override
    public List<ApplyEntity> zhexiantu(String id) {
        List<ApplyEntity> list = this.list(new QueryWrapper<ApplyEntity>().eq("pet_id", id).orderByAsc("end_time"));
        if (list.size()>10){
            return list.subList(0,10);
        }
        return list;
    }

}